home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gnome-pilot.idb / usr / freeware / share / gob / gnome-pilot-conduit-config.gob.z / gnome-pilot-conduit-config.gob
Text File  |  2001-10-09  |  11KB  |  361 lines

  1. /* gnome-pilot-conduit-config.gob
  2.  *
  3.  * Copyright (C) 1999-2000 Free Software Foundation
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the
  17.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.  * Boston, MA 02111-1307, USA.
  19.  *
  20.  * Authors: Eskil Heyn Olsen
  21.  *          Vadim Strizhevsky
  22.  *
  23.  */
  24.  
  25. /* GOB version requirement */
  26. requires 0.92.4
  27.  
  28. %h{
  29. #include <glib.h>
  30. #include <gtk/gtkobject.h>
  31. #include <gpilotd/gnome-pilot-conduit.h>
  32. #include <libgpilotdCM/gnome-pilot-conduit-management.h>
  33. #include <gmodule.h>
  34. %}
  35.  
  36. %{
  37. #include <config.h>
  38. %}
  39.  
  40. class Gnome:Pilot:Conduit:Config from Gtk:Object {
  41.     public GnomePilotConduitSyncType sync_type;
  42.     public GnomePilotConduitSyncType first_sync_type;
  43.     public gboolean first_slow;
  44.  
  45.     private guint32 pilot_id;
  46.     private GnomePilotConduitManagement *gpcm;
  47.  
  48.     /***************************/
  49.     /* Initialization          */
  50.     /***************************/
  51.  
  52.     /* This loads a conduit of a specific type */
  53.     public GnomePilotConduitConfig*
  54.     new(GnomePilotConduitManagement *gpcm, guint32 pilot_id) {
  55.         GtkObject *ret = NULL;
  56.         GnomePilotConduitConfig *obj;
  57.  
  58.         ret = GTK_OBJECT(GET_NEW);
  59.         obj = SELF(ret);
  60.         obj->_priv->pilot_id = pilot_id;
  61.         obj->_priv->gpcm = gpcm;
  62.  
  63.         return obj;
  64.     }
  65.     
  66.     /* Destroys this instance of sefl */
  67.         public void
  68.     destroy(self) {
  69.         gtk_object_destroy(GTK_OBJECT(self));
  70.     }
  71.  
  72.     /***********************************/
  73.     /* CONFIG LOAD/STORE               */
  74.     /***********************************/
  75.  
  76.     /* Sets the variables to reflect the stat */
  77.     public int
  78.     load_config(self) onerror 0 {
  79.         gchar *prefix,*tmp;
  80.  
  81.         if(is_enabled(self,NULL)==TRUE) {
  82.             prefix = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  83.                          self->_priv->pilot_id,
  84.                                  gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  85.             gnome_config_push_prefix(prefix);
  86.             tmp = gnome_config_get_string("sync_type");
  87.             if (tmp) {
  88.                 self->sync_type = gnome_pilot_conduit_sync_type_str_to_int(tmp);
  89.             } else {
  90.                 g_warning("conduit has no sync_type, synchronization will skip this conduit");
  91.                 self->sync_type = GnomePilotConduitSyncTypeNotSet;
  92.             }
  93.             g_free(tmp);
  94.             tmp = gnome_config_get_string("first_sync_type");
  95.             if (tmp) {
  96.                 self->first_sync_type = gnome_pilot_conduit_sync_type_str_to_int(tmp);
  97.             } else {
  98.                 self->first_sync_type = GnomePilotConduitSyncTypeNotSet;
  99.             }
  100.             g_free(tmp);
  101.             self->first_slow = gnome_config_get_bool("slow_sync");
  102.             gnome_config_pop_prefix();
  103.             g_free(prefix);
  104.         } else 
  105.             return 0;
  106.         return 1;
  107.     } 
  108.  
  109.     public int
  110.     save_config(self) onerror 0 {
  111.         gchar *prefix;
  112.  
  113.         if(is_enabled(self,NULL)==TRUE) {
  114.             prefix = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  115.                          self->_priv->pilot_id,
  116.                                  gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  117.             gnome_config_push_prefix(prefix);
  118.             gnome_config_set_string("sync_type",
  119.                         gnome_pilot_conduit_sync_type_int_to_str(self->sync_type));
  120.             gnome_config_set_string("first_sync_type",
  121.                         gnome_pilot_conduit_sync_type_int_to_str(self->first_sync_type));
  122.             if(self->first_sync_type==GnomePilotConduitSyncTypeSynchronize) 
  123.                     gnome_config_set_bool("slow_sync",self->first_slow);
  124.             else
  125.                     gnome_config_clean_key("slow_sync");
  126.             gnome_config_pop_prefix();
  127.             gnome_config_sync();
  128.             g_free(prefix);
  129.         } else 
  130.             return 0;
  131.         return 1;
  132.     }
  133.  
  134.     /***********************************/
  135.     /* CONDUIT EN/DIS-ABLING AND SUCH  */
  136.     /***********************************/
  137.  
  138.     /* Checks if the conduit is enabled for pilot pilot_id,
  139.        in which case return val is TRUE, and sync_type
  140.        if not null set to the sync type */
  141.     public gboolean
  142.     is_enabled(self, 
  143.            GnomePilotConduitSyncType *sync_type) {
  144.         gchar *tmp;
  145.         int num_conduits,cnt;
  146.         gchar **conduit_name;
  147.         gboolean retval;
  148.         
  149.         retval = FALSE;
  150.         
  151.         tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",
  152.                       self->_priv->pilot_id);
  153.         /* g_message("prefix = %s",tmp); */
  154.         
  155.         /* load the list */
  156.         gnome_config_push_prefix(tmp);
  157.         gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
  158.         gnome_config_pop_prefix();
  159.         
  160.         /* g_message("number_of_conduits = %d",num_conduits); */
  161.         
  162.         /* loop, compare and free */
  163.         for(cnt=0;cnt<num_conduits;cnt++) {
  164.             /* g_message("g_str_equal(%s,%s)",
  165.                conduit_name[cnt] ,
  166.                gnome_pilot_conduit_management_get_id(self->_priv->gpcm)); */
  167.             if(g_str_equal(conduit_name[cnt] ,gnome_pilot_conduit_management_get_id(self->_priv->gpcm))) {
  168.                 /* g_message("match on %s, it is enabled",conduit_name[cnt]); */
  169.                 if(sync_type) {
  170.                     gchar *newpfx,*tmpstr;
  171.                     newpfx = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/sync_type",
  172.                                  self->_priv->pilot_id,
  173.                                  gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  174.                     tmpstr = gnome_config_get_string(newpfx);
  175.                     /* g_message("%s says %s",newpfx,tmpstr); */
  176.                     (*sync_type) = gnome_pilot_conduit_sync_type_str_to_int(tmpstr);
  177.                     g_free(newpfx);
  178.                     g_free(tmpstr);
  179.                 }
  180.                 retval = TRUE;
  181.             } 
  182.             g_free(conduit_name[cnt]);
  183.         }
  184.         g_free(conduit_name);
  185.         g_free(tmp);
  186.         return retval;
  187.     }
  188.  
  189.     /* enable the conduit for pilot pilot_id
  190.        with the specified synctype */
  191.         public void
  192.     enable(self,
  193.            GnomePilotConduitSyncType sync_type) {
  194.         gchar *tmp;
  195.         char **conduit_name;
  196.         char **conduit_name_copy;
  197.         int num_conduits,cnt;
  198.     
  199.         /* enable conduit, if it wasn't, otherwise, just write
  200.            the sync type in case it was changed. */
  201.         if(is_enabled(self,NULL)==FALSE) {
  202.             tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",self->_priv->pilot_id);
  203.             /* g_message("prefix = %s",tmp); */
  204.     
  205.             /* load the list of conduits */
  206.             gnome_config_push_prefix(tmp);
  207.             gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
  208.             /* g_message("num_conduits = %d",num_conduits); */
  209.     
  210.             /* copy the list and attach new conduit */
  211.             conduit_name_copy = g_new0(gchar*,num_conduits+2);
  212.             for(cnt=0;cnt<num_conduits;cnt++) {
  213.                 /* g_message("duping %d %s",cnt,conduit_name[cnt]); */
  214.                 conduit_name_copy[cnt] = g_strdup(conduit_name[cnt]);
  215.                 g_free(conduit_name[cnt]);
  216.             }
  217.             g_free(conduit_name);
  218.             /* g_message("adding %s as element %d",gnome_pilot_conduit_management_get_id(self->_priv->gpcm),num_conduits); */ 
  219.             conduit_name_copy[num_conduits] = g_strdup(gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  220.     
  221.             /* write new list */
  222.             /* g_message("writing new conduits list, size %d",num_conduits+1); */
  223.             gnome_config_set_vector("conduits",num_conduits+1,(const char**)conduit_name_copy);
  224.     
  225.             /* free the copy */
  226.             /* g_message("freeing %d items",num_conduits+1); */
  227.             for(cnt=0;cnt<num_conduits+1;cnt++) {
  228.                 /* g_message("should contain %s",conduit_name_copy[cnt]); */
  229.                 g_free(conduit_name_copy[cnt]);
  230.             }
  231.             g_free(conduit_name_copy);
  232.     
  233.             gnome_config_pop_prefix();
  234.     
  235.             g_free(tmp);
  236.         }
  237.  
  238.         /* make section for conduit */
  239.         tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  240.                       self->_priv->pilot_id,
  241.                       gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  242.         /* g_message("prefix = %s",tmp); */
  243.         gnome_config_push_prefix(tmp);
  244.         gnome_config_set_string("sync_type",
  245.                     gnome_pilot_conduit_sync_type_int_to_str(sync_type));
  246.         gnome_config_pop_prefix();
  247.         gnome_config_sync();
  248.         g_free(tmp);
  249.     }
  250.  
  251.     /* enable the conduit for pilot pilot_id
  252.        with the specified synctype */
  253.     public void
  254.     enable_with_first_sync(self,
  255.                    GnomePilotConduitSyncType sync_type,
  256.                    GnomePilotConduitSyncType first_sync_type,
  257.                    gboolean slow) {
  258.         gchar *tmp;
  259.         
  260.         enable(self,sync_type);
  261.  
  262.         /* add the first_sync info */
  263.         tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  264.                       self->_priv->pilot_id,
  265.                       gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  266.         gnome_config_push_prefix(tmp);
  267.         gnome_config_set_string("first_sync_type",
  268.                     gnome_pilot_conduit_sync_type_int_to_str(first_sync_type));
  269.         if(first_sync_type==GnomePilotConduitSyncTypeSynchronize) 
  270.             gnome_config_set_bool("slow_sync",slow);
  271.         else
  272.             gnome_config_clean_key("slow_sync");
  273.         gnome_config_pop_prefix();
  274.         gnome_config_sync();
  275.         g_free(tmp);
  276.     }
  277.  
  278.     /* clear the first sync flag, if the conduit is not enabled, */
  279.     public void
  280.     remove_first_sync(self) {
  281.         gchar *tmp;
  282.         
  283.         if (is_enabled(self,NULL)) {
  284.             /* add the first_sync info */
  285.             tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  286.                           self->_priv->pilot_id,
  287.                           gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  288.             if (gnome_config_has_section(tmp)) {
  289.                 gnome_config_push_prefix(tmp);
  290.                 gnome_config_clean_key("first_sync_type");
  291.                 gnome_config_clean_key("slow_sync");
  292.                 gnome_config_pop_prefix();
  293.             }
  294.             gnome_config_sync();
  295.             g_free(tmp);
  296.         }
  297.  
  298.         
  299.     }
  300.        
  301.     /* disable the conduit for the pilot */
  302.     public void
  303.     disable(self) {
  304.         gchar *tmp;
  305.         gchar **conduit_name;
  306.         char **conduit_name_copy;
  307.         int num_conduits,num_conduits_copy,cnt;
  308.         
  309.         if(is_enabled(self,NULL)==FALSE) return;
  310.  
  311.         tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",self->_priv->pilot_id);
  312.         
  313.         /* load the list of conduits */
  314.         gnome_config_push_prefix(tmp);
  315.         gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
  316.         
  317.         /* copy the list, excluding the one to delete, num_conduits is > 0 since is_enables succeeded */
  318.         conduit_name_copy = g_new0(char*,num_conduits);
  319.         num_conduits_copy = 0;
  320.         for(cnt=1;cnt<num_conduits;cnt++) {
  321.             if(g_strcasecmp(conduit_name[cnt],gnome_pilot_conduit_management_get_id(self->_priv->gpcm))) {
  322.                 /* g_message("keeping %d:%s",cnt,conduit_name[cnt]); */
  323.                 conduit_name_copy[num_conduits_copy]=g_strdup(conduit_name[cnt]);
  324.                 num_conduits_copy++;
  325.             } else {
  326.                 /* g_message("skipping %d:%s",cnt,conduit_name[cnt]); */
  327.             }
  328.             g_free(conduit_name[cnt]);
  329.         }
  330.         g_free(conduit_name);
  331.         
  332.         /* save new list */
  333.         /* g_message("num_conduits_copy = %d",num_conduits_copy); */
  334.         if ( num_conduits_copy > 0 )
  335.             gnome_config_set_vector("conduits",num_conduits_copy,(const char**)conduit_name_copy);
  336.         else
  337.             gnome_config_clean_key("conduits");
  338.         
  339.         /* free copy */
  340.         for(cnt=0;cnt<num_conduits_copy;cnt++) g_free(conduit_name_copy[cnt]);
  341.         g_free(conduit_name_copy);
  342.         
  343.         gnome_config_pop_prefix();
  344.         
  345.         /* nuke the conduits config section */
  346.         g_free(tmp);
  347.         tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
  348.                       self->_priv->pilot_id,
  349.                       gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
  350.         gnome_config_clean_section(tmp);
  351.         
  352.         gnome_config_sync();
  353.         g_free(tmp);        
  354.     }
  355. }
  356.  
  357. %{
  358.  
  359. %}
  360.  
  361.